package my.controller;

import com.jfinal.core.Controller;
import my.model.Message;

import java.util.List;


/**
 * Created by Administrator on 2017/4/13 0013.
 */
public class MessageController extends Controller {
    public void index() {
        list();
    }

    public void list() {
        List<Message> messages = Message.dao.find("SELECT * FROM message");
        setAttr("messages",messages);
        renderFreeMarker("list-new.ftl");
    }

    public void save() {
        Message message=new Message();
        String title = getPara("message.title");
        String author = getPara("message.author");
        String content = getPara("message.content");
        message.setTitle(title);
        message.setAuthor(author);
        message.setContent(content);
        message.save();
        redirect("/message/list");
    }

    public void create() {
        String username=getSessionAttr("username");
        if(username==null)
        {
            redirect("/login");
        }
        else
            renderFreeMarker("create-new.ftl");
    }
}
